//Berechnung des Abtastzeitvektors
#include "tS.h"


void calcSamplingTime(sampling * s, int * dt0)
{
	//----------------------Initialisieren-----------------------------------//
	s->numberOfPulsesPerBurst = 8;				//ZUM EINGEBEN
	s->numberOfBursts = 3;					//ZUM EINGEBEN
	s->staggerFactor = (int *)calloc(s->numberOfBursts, sizeof(int));
	s->timeBurstPauseRel = (int *)calloc(s->numberOfBursts, sizeof(int));
	s->staggerFactor[0] = 19;				//ZUM EINGEBEN
	s->staggerFactor[1] = 22;				//ZUM EINGEBEN
	s->staggerFactor[2] = 25;				//ZUM EINGEBEN
	s->timeBurstPauseRel[0] = 2 * (*dt0);			//ZUM EINGEBEN
	s->timeBurstPauseRel[1] = 2 * (*dt0);			//ZUM EINGEBEN
	s->timeBurstPauseRel[2] = 2 * (*dt0);			//ZUM EINGEBEN

	s->df = (float *)calloc(s->numberOfBursts, sizeof(float));
	s->tObservation = (float *)calloc(s->numberOfBursts, sizeof(float));
	s->fNyquist = (float *)calloc(s->numberOfBursts, sizeof(float));
	//----------------------Initialisieren-----------------------------------//


	double *staggerratio = (double *)calloc(s->numberOfBursts, sizeof(double));
	for(int i = 0; i < s->numberOfBursts; i++)
		staggerratio[i] = (double) s->staggerFactor[i] / s->staggerFactor[0];

	s->N = s->numberOfBursts * s->numberOfPulsesPerBurst;

	s->t = (double *)calloc(s->N, sizeof(double));

	int index = 0;
	double time = 0;
	
	for(int burst = 0; burst < s->numberOfBursts; burst++)
	{
		double dt = staggerratio[burst]* (*dt0);
		double tStart = time;
		for(int pulses = 0; pulses < s->numberOfPulsesPerBurst; pulses++)
		{
			s->t[index] = time; 
			index++;
			time += dt;
		}
		time -= dt;
		double tEnd = time;
		time += s->timeBurstPauseRel[burst]; 
		s->fNyquist[burst] = 1 / (2*dt); 
		s->tObservation[burst] = tEnd - tStart; 
		s->df[burst] = 1 / s->tObservation[burst]; 
	}

	//-------------------------------Ergebnisse-------------------//
	s->tObservationTotal = s->t[s->N-1] - s->t[0];
	s->fNyquistTotal = s->N / (2*s->tObservationTotal);
	//-------------------------------Ergebnisse-------------------//

}
